package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.base.TabVerViewHolder;
import com.kaiyiweitong.tongxing.bean.IntegralTypeResData;

import java.util.List;

/**
 * Created by Administrator on 2017/12/17 0017.
 */

public class IntegralTypeAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private final LayoutInflater mInflater;
    private OnClickListener mListener;
    private List<IntegralTypeResData> mData;
    private int mSelect;

    public interface OnClickListener {
        void onClick(int position);
    }

    public IntegralTypeAdapter(Context context, List<IntegralTypeResData> typeData, OnClickListener listener, int position) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mListener = listener;
        mData = typeData;
        mSelect = position;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_classify_ver, null);
        TabVerViewHolder myViewHolder = new TabVerViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        TabVerViewHolder viewHolder = (TabVerViewHolder) holder;
        viewHolder.name.setText(mData.get(position).getName());
        viewHolder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(position);
            }
        });

        if (mSelect == position) {
            viewHolder.name.setSelected(true);
        }
    }

    @Override
    public int getItemCount() {
        if (mData != null && mData.size() > 0) {
            return mData.size();
        } else {
            return 0;
        }
    }
}
